﻿@using SCMS.Resource
@model SCMS.UI.Models.POModel
@{
    int itemCount = Model.ORTenderItems.Count == null ? 0 : Model.ORTenderItems.Count;
    AjaxOptions ajaxOpts = new AjaxOptions
    {
        UpdateTargetId = "PODiv",
        LoadingElementId = "loading",
        HttpMethod = "Post",
        Url = Url.Action("SavePOTender"),
        OnBegin = "return VerifyEditPO(" + itemCount + ")"
    };
}
<script src="@Url.Content("~/Scripts/js/jquery-1.7.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<div class="partialViewCard">
    <div class="partialViewCardHeader">
        <h3>New PO:: &nbsp;@Model.POEntiy.RefNumber&nbsp;(from TA)</h3>
    </div>
    @using (Ajax.BeginForm(null, null, ajaxOpts, new { @class = "form" }))
    {
        @Html.ValidationSummary(true)
        <br />
        <table width="98%" align="center" style="margin-left: auto; margin-right: auto;">
            <tr>
                <th width="33%">
                    @Resources.Global_String_Date
                </th>
                <th width="33%">
                    @Resources.Global_String_TenderAnalyaisNo
                </th>
                <th width="34%">
                    @Resources.Global_String_OrderRequestNo
                </th>
            </tr>
            <tr>
                <td>
                    @Html.EditorFor(m => m.PODate)
                    @Html.ValidationMessageFor(m => m.PODate)
                </td>
                <td>
                    @if (Model.TAID == Guid.Empty)
                    {
                        @Html.DropDownListFor(x => x.TAID, Model.TAnalysis, Resources.Global_String_PleaseSelect, new { id = "dpltenderanalysis", onchange = "javascript:GetTAnalysis(this)" })
                    }
                    else
                    { 
                        @Html.DropDownListFor(x => x.TAID, Model.TAnalysis, new { id = "dpltenderanalysis", onchange = "javascript:GetTAnalysis(this)" })
                    }                    
                    @Html.ValidationMessageFor(x => x.TAID)
                </td>
                <td align="center">
                    @Html.HiddenFor(x => x.POEntiy.OrderRequestId)
                    @foreach (var or in Model.OrderRequests)
                    {
                        if (or.Value == Model.POEntiy.OrderRequestId.ToString())
                        { 
                            @or.Text
                       break;
                        }
                    }
                </td>
            </tr>
            <tr>
                <th>
                    @Resources.Budget_CategoryList_ProjectNo
                </th>
                <th>
                    @Resources.PurchaseOrder_String_QuotationRef
                </th>
                <th>
                    @Resources.GoodsReceivedNote_LoadGRNVerifyItems_DeliveryDate
                </th>
            </tr>
            <tr>
                <td align="center">
                    @ViewBag.ProjectNo
                    @Html.HiddenFor(model => model.POEntiy.RefNumber)
                </td>
                <td>
                    @Html.TextBoxFor(model => model.QuatationRef)                    
                    @Html.ValidationMessageFor(model => model.QuatationRef, Resources.Global_String_Required)
                </td>
                <td>@Html.EditorFor(model => model.deliveryDate)
                    @Html.ValidationMessageFor(model => model.deliveryDate)
                </td>
            </tr>
            <tr>
                <th>
                    @Resources.PurchaseOrder_EditPO_ToSupplier
                </th>
                <th>
                    @Resources.Global_String_DeliveryAddress
                </th>
                <th>
                    @Resources.Global_String_DRCRemarks
                </th>
            </tr>
            <tr>
                <td align="center">
                    @Html.HiddenFor(x => x.supplierID)
                    @foreach (var supplier in Model.suppliers)
                    {
                        if (supplier.Value == Model.supplierID.ToString())
                        { 
                            @supplier.Text
                       break;
                        }
                    }
                </td>
                <td align="center">
                    @Html.HiddenFor(x => x.deliveryAddressID)
                    @foreach (var location in Model.deliveryAddress)
                    {
                        if (location.Value == Model.deliveryAddressID.ToString())
                        { 
                            @location.Text
                       break;
                        }
                    }
                </td>
                <td>
                    @Html.EditorFor(model => model.POEntiy.Remarks)
                </td>
            </tr>
            <tr>
                <th>
                    @Resources.Global_String_ShippingTerms
                </th>
                <th>
                    @Resources.Global_String_PaymentTerms
                </th>
                <th>
                    @Resources.Global_String_Currency
                </th>
            </tr>
            <tr>
                <td>
                    @Html.DropDownListFor(x => x.shippingTerm, Model.ShippingTerms, Resources.Global_String_PleaseSelect)
                    @Html.ValidationMessageFor(x => x.shippingTerm)
                </td>
                <td>
                    @Html.DropDownListFor(x => x.paymentTerm, Model.PaymentTerms, Resources.Global_String_PleaseSelect)
                    @Html.ValidationMessageFor(x => x.paymentTerm)
                </td>
                <td align="center">
                    @ViewBag.Currency
                    <input type="hidden" id="currencyId" value="@ViewBag.CurrencyId" />
                </td>
            </tr>
        </table>
        <h4 style="text-align: center;">
            @Resources.PurchaseOrder_String_PurchaseOrderItems</h4>
        <hr />
        <p id="budgetCheckStatus">
        </p>
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
            <tr class="grideven">
                <th>
                    @Resources.Global_String_Item
                </th>
                <th>
                    @Resources.Global_String_Description
                </th>
                <th>
                    @Resources.Global_String_Qty
                </th>
                <th>
                    @Resources.PurchaseOrder_AddPOItems_UnitPrice
                </th>
                <th>
                    @Resources.PurchaseOrder_AddPOItems_TotalPrice
                </th>
                <th>
                    @Resources.Budget_CreateSubLine_LineNumber
                </th>
                <th>
                    @Resources.Global_String_Remarks
                </th>
            </tr>
            @{ 
                string row = "";
                int count = 0;
                if (Model.IncludesTransportCost)
                {
                    count = Model.ORTenderItems.Count - 1;
                }
                else
                {
                    count = Model.ORTenderItems.Count;
                }
            }
            @for (int i = 0; i < count; i++)
            {
                row = "row" + i;
                <tr id="@row">
                    <td style="width: 17%;">
                        @Model.ORTenderItems[i].ItemName
                        @Html.HiddenFor(m => m.ORTenderItems[i].TBQuoteEntity.OrderRequestItemId, new { @id = "orItem" + i })
                    </td>
                    <td style="width: 25%;">
                        @Model.ORTenderItems[i].TBQuoteEntity.OrderRequestItem.ItemDescription
                    </td>
                    <td style="width: 8%;">
                        @Html.TextBoxFor(m => m.ORTenderItems[i].TBQuoteEntity.OrderRequestItem.Quantity, new { id = "quantity" + i, onblur = "javascript:computePOItemTotals(" + i + ")", @class = "numericTb" })
                    </td>
                    <td style="width: 10%;">
                        @Html.TextBoxFor(m => m.ORTenderItems[i].TBQuoteEntity.UnitPrice, new { id = "unitPrice" + i, onblur = "javascript:computePOItemTotals(" + i + ")", @class = "numericTb" })
                    </td>
                    <td style="width: 10%;">
                        @Html.TextBoxFor(m => m.ORTenderItems[i].TotalCost, new { id = "totalPrice" + i, @class = "numericTb", @readonly = "readonly" })
                    </td>
                    <td style="width: 15%;" align="center">
                        @Html.DropDownListFor(m => m.ORTenderItems[i].BudgetLineId, new SelectList(Model.ORTenderItems[i].BudgetLines, "Id", "Description", Model.ORTenderItems[i].TBQuoteEntity.OrderRequestItem.BudgetLineId),
                            new { @id = "blId" + i, onchange = "javascript:checkBLBalance(" + i + ")" })
                    </td>
                    <td style="width: 15%;">
                        @Html.TextBoxFor(m => m.ORTenderItems[i].TBQuoteEntity.OrderRequestItem.Remarks, new { @class = "poTextBox" })
                    </td>
                </tr>
            }
            @if (Model.IncludesTransportCost)
            {
                int i = count;
                row = "row" + i;
                <tr id="@row">
                    <td style="width: 17%;">
                        @Model.ORTenderItems[i].TransportDescription                        
                    </td>
                    <td style="width: 25%;">
                        From TA
                    </td>
                    <td style="width: 8%;">
                        @Html.TextBoxFor(m => m.ORTenderItems[i].TransportQty, new { id = "quantity" + i, @readonly = "readonly", onblur = "javascript:computePOItemTotals(" + i + ")", @class = "numericTb" })
                    </td>
                    <td style="width: 10%;">
                        @Html.TextBoxFor(m => m.ORTenderItems[i].TransportUnitCost, new { id = "unitPrice" + i, onblur = "javascript:computePOItemTotals(" + i + ")", @class = "numericTb" })
                    </td>
                    <td style="width: 10%;">
                        @Html.TextBoxFor(m => m.ORTenderItems[i].TotalCost, new { id = "totalPrice" + i, @class = "numericTb", @readonly = "readonly" })
                    </td>
                    <td style="width: 15%;" align="center">
                        @Html.DropDownListFor(m => m.ORTenderItems[i].BudgetLineId, new SelectList(Model.ORTenderItems[i].BudgetLines, "Id", "Description"),
                            new { @id = "blId" + i, onchange = "javascript:checkBLBalance(" + i + ")" })
                    </td>
                    <td style="width: 15%;">
                        @Html.TextBoxFor(m => m.ORTenderItems[i].TransportRemarks, new { @class = "poTextBox" })
                    </td>
                </tr>
            }
        </table>
        <table width="98%" align="center">
            <tr>
                <td width="50%">
                    @Ajax.ActionLink("<<" + Resources.Global_String_Back, "Index", new { id = "ChoosePOTye" }, new AjaxOptions
               {
                   UpdateTargetId = "PODiv",
                   LoadingElementId = "loading",
                   Url = Url.Action("ChoosePOTye")
               })
                </td>
                <td width="50%" align="right">
                    @Html.HiddenFor(p => p.IncludesTransportCost)
                    <input type="submit" class="btn green" value="@Resources.Global_String_Proceed" />
                </td>
            </tr>
        </table>
    }
</div>
